<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="<?php echo __PUBLIC__ ?>/css/bootstrap.min.css">

	<style type="text/css">
		.main{
			padding-top: 80px;
		}
		.form-inline .content{
			margin-top: 20px;
			margin-bottom: 20px;
			width: 100%;
		}
	</style>
</head>
<body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="./index.php">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
        <?php if (isset($_SESSION['username'])) { ?>
            <div class='navbar-form navbar-right'>
            <p class="btn alert-danger"><?php echo $_SESSION['nikename'] ?></p>
            <a class="btn btn-success" href="./loginout.php">退出</a>
            </div>
        <?php }else{ ?>
          
          <form action="./login.php" method="post" class="navbar-form navbar-right" >
            <div class="form-group">
              <input type="text" placeholder="用户名" name="username" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="密码" name="password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">登陆</button>
            <a class="btn btn-info" href="./index.php?m=home&c=reg&a=index">注册</a>
          </form>

        <?php } ?>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>

    

    <div class="col-md-12 main">
      <!-- 分页开始 -->
        <!-- <nav aria-label="Page navigation">
          <ul class="pagination">
            <?php if ($page<>1) { ?>
              <li>
                <a href="./index.php?p=<?php echo $page-1 ?>" aria-label="Previous">
                  <span aria-hidden="true">&laquo;</span>
                </a>
              </li>
            <?php } ?>
        
            <?php for ($i=1; $i <= $pages ; $i++) { ?>
              <li><a href="./index.php?p=<?php echo $i ?>"><?php echo $i ?></a></li>
            <?php } ?>
            
            <?php if ($page<>$pages) { ?>
              <li>
                <a href="./index.php?p=<?php echo $page+1 ?>" aria-label="Next">
                  <span aria-hidden="true">&raquo;</span>
                </a>
              </li>
            <?php } ?>
            
          </ul>
        </nav> -->
      <!-- 分页结束 -->

    <?php foreach ($msgs as $k => $v) { ?>
    	<div class="alert <?php echo $color[array_rand($color)]?> msgrow" role="alert">
      		<strong><?php echo $v['username'] ?></strong> <?php echo $v['content'] ?> （<?php echo date('Y-m-d H:i:s',$v['create_time']) ?>）
      		<!--未用异步的删除 <a href="./del.php?id=<?php echo $k ?>" class="btn btn-warning">删除</a> -->
          
          <button ybid="<?php echo $k ?>"  class="btn btn-warning del">删除</button>
      		<a href="./index.php?m=home&c=index&a=edit&id=<?php echo $v['id'] ?>" class="btn btn-info">修改</a>
          
    	</div>
	  <?php } ?>

    </div>
    <div class="col-md-12">
		<form class="form-inline" method="post" action="./add.php">
			<div class="col-md-12">
				<div class="form-group">
				    <label for="exampleInputName2">用户名</label>
				    <input type="text" class="form-control" name="username" id="exampleInputName2" placeholder="Jane Doe">
				</div>
				<button type="submit" class="btn btn-success">发布留言</button>
			</div>
			<div class="col-md-12">
				<textarea class="form-control content" name="content" cols="30" rows="10"></textarea>
			</div>
		</form>
    </div>
    <script type="text/javascript" src="../../jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
          
          $('.del').click(function(event) {
            var id = $(this).attr("ybid");
            alert(id);
            del = $(this);
            $.ajax({
              url: './ajaxdel.php',
              type: 'post',
              dataType: 'json',
              data: {msgid: id},
            })
            .done(function(data) {
              if(data.error==0){
                alert(data.info);
                del.parents('.msgrow').remove();
              }
            })
            .fail(function(data) {
              alert("失败");
            })
          });

        })












    </script>
</body>
</html>